package com.open.capacity.reptile.controller;

import java.util.Map;

import com.open.capacity.commons.Result;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.reptile.entity.GdszczMaEleCurrent;
import com.open.capacity.reptile.service.GdszczMaEleCurrentService;

import javax.validation.Valid;

import com.open.capacity.commons.PageResult;

/**
 * 往来单位
 *
 * @author
 * @email
 * @date 2023-10-17 15:54:43
 */
@RestController
@RequestMapping("gdszczmaelecurrent")
@Api(tags = "往来单位")
public class GdszczMaEleCurrentController {

    @Autowired
    private GdszczMaEleCurrentService gdszczMaEleCurrentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('gdszcz_ma_ele_current:gdszczmaelecurrent:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = gdszczMaEleCurrentService.pageAll(params);
        return pageResult;
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('gdszcz_ma_ele_current:gdszczmaelecurrent:list')")
    public Result findById(String id) {
        return Result.succeed(gdszczMaEleCurrentService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('gdszcz_ma_ele_current:gdszczmaelecurrent:save')")
    public Result save(@RequestBody @Valid GdszczMaEleCurrent gdszczMaEleCurrent, String keyValue) {
        if (StringUtils.isEmpty(keyValue)) {
            gdszczMaEleCurrentService.save(gdszczMaEleCurrent);
        } else {
        }
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('gdszcz_ma_ele_current:gdszczmaelecurrent:delete')")
    public Result delete(@PathVariable String chrId) {
        gdszczMaEleCurrentService.delete(chrId);
        return Result.succeed("删除成功");
    }

}
